From 7480fb703e3b8569d20a20236347c6d4e0873c26 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 28 May 2020 14:54:57 +0100 Subject: [PATCH] a11y: Simplify GtkNotebookAccessible Let the GtkNotebook explicitly update the accessible object that the current page has changed, instead of overriding GtkWidgetAccessible.notify_gtk. --- gtk/a11y/gtknotebookaccessible.c | 73 ++++++++++--------------- gtk/a11y/gtknotebookaccessibleprivate.h | 30 ++++++++++ gtk/gtknotebook.c | 10 +++- 3 files changed, 66 insertions(+), 47 deletions(-) create mode 100644 gtk/a11y/gtknotebookaccessibleprivate.h diff --git a/gtk/a11y/gtknotebookaccessible.c b/gtk/a11y/gtknotebookaccessible.c index 75d8188213..468e2a4206 100644 --- a/gtk/a11y/gtknotebookaccessible.c +++ b/gtk/a11y/gtknotebookaccessible.c @@ -17,10 +17,12 @@ #include "config.h" -#include -#include -#include "gtknotebookaccessible.h" +#include "gtknotebookaccessibleprivate.h" + #include "gtknotebookpageaccessible.h" +#include "gtknotebook.h" + +#include struct _GtkNotebookAccessiblePrivate { @@ -153,55 +155,41 @@ gtk_notebook_accessible_ref_child (AtkObject *obj, return child; } -static void -gtk_notebook_accessible_notify_gtk (GObject *obj, - GParamSpec *pspec) +void +gtk_notebook_accessible_update_page (GtkNotebookAccessible *self, + int page_num) { - GtkWidget *widget; - AtkObject* atk_obj; + GtkNotebookAccessiblePrivate *priv = gtk_notebook_accessible_get_instance_private (self); + AtkObject *atk_obj = ATK_OBJECT (self); + int old_page_num = priv->selected_page; - widget = GTK_WIDGET (obj); - atk_obj = gtk_widget_get_accessible (widget); + priv->selected_page = page_num; - if (strcmp (pspec->name, "page") == 0) + /* Notify SELECTED state change for old and new page */ + if (page_num != old_page_num) { - gint page_num, old_page_num; - GtkNotebookAccessible *accessible; - GtkNotebook *notebook; - - accessible = GTK_NOTEBOOK_ACCESSIBLE (atk_obj); - notebook = GTK_NOTEBOOK (widget); - - /* Notify SELECTED state change for old and new page */ - old_page_num = accessible->priv->selected_page; - page_num = gtk_notebook_get_current_page (notebook); - accessible->priv->selected_page = page_num; + AtkObject *child; - if (page_num != old_page_num) + if (old_page_num != -1) { - AtkObject *child; - - if (old_page_num != -1) - { - child = gtk_notebook_accessible_ref_child (atk_obj, old_page_num); - if (child) - { - atk_object_notify_state_change (child, ATK_STATE_SELECTED, FALSE); - g_object_unref (child); - } - } - child = gtk_notebook_accessible_ref_child (atk_obj, page_num); - if (child) + child = gtk_notebook_accessible_ref_child (atk_obj, old_page_num); + if (child != NULL) { - atk_object_notify_state_change (child, ATK_STATE_SELECTED, TRUE); + atk_object_notify_state_change (child, ATK_STATE_SELECTED, FALSE); g_object_unref (child); } - g_signal_emit_by_name (atk_obj, "selection-changed"); - g_signal_emit_by_name (atk_obj, "visible-data-changed"); } + + child = gtk_notebook_accessible_ref_child (atk_obj, page_num); + if (child != NULL) + { + atk_object_notify_state_change (child, ATK_STATE_SELECTED, TRUE); + g_object_unref (child); + } + + g_signal_emit_by_name (atk_obj, "selection-changed"); + g_signal_emit_by_name (atk_obj, "visible-data-changed"); } - else - GTK_WIDGET_ACCESSIBLE_CLASS (gtk_notebook_accessible_parent_class)->notify_gtk (obj, pspec); } /* @@ -230,14 +218,11 @@ gtk_notebook_accessible_class_init (GtkNotebookAccessibleClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); AtkObjectClass *class = ATK_OBJECT_CLASS (klass); - GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass; gobject_class->finalize = gtk_notebook_accessible_finalize; class->ref_child = gtk_notebook_accessible_ref_child; class->initialize = gtk_notebook_accessible_initialize; - - widget_class->notify_gtk = gtk_notebook_accessible_notify_gtk; } static void diff --git a/gtk/a11y/gtknotebookaccessibleprivate.h b/gtk/a11y/gtknotebookaccessibleprivate.h new file mode 100644 index 0000000000..5e4ab3b9f5 --- /dev/null +++ b/gtk/a11y/gtknotebookaccessibleprivate.h @@ -0,0 +1,30 @@ +/* gtknotebookaccessibleprivate.h: GtkNotebookAccessible private API + * + * Copyright 2020 GNOME Foundation + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#pragma once + +#include "gtknotebookaccessible.h" + +G_BEGIN_DECLS + +void gtk_notebook_accessible_update_page (GtkNotebookAccessible *self, + int page_num); + +G_END_DECLS diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 08beb715a8..7ccaf47a67 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -55,7 +55,7 @@ #include "gtkwidgetpaintable.h" #include "gtknative.h" -#include "a11y/gtknotebookaccessible.h" +#include "a11y/gtknotebookaccessibleprivate.h" #include #include @@ -5298,6 +5298,7 @@ gtk_notebook_real_switch_page (GtkNotebook *notebook, { GList *list = gtk_notebook_find_child (notebook, GTK_WIDGET (child)); GtkNotebookPage *page = GTK_NOTEBOOK_PAGE_FROM_LIST (list); + AtkObject *accessible; gboolean child_has_focus; if (notebook->cur_page == page || !gtk_widget_get_visible (GTK_WIDGET (child))) @@ -5343,6 +5344,11 @@ gtk_notebook_real_switch_page (GtkNotebook *notebook, update_arrow_state (notebook); + accessible = _gtk_widget_peek_accessible (GTK_WIDGET (notebook)); + if (accessible != NULL) + gtk_notebook_accessible_update_page (GTK_NOTEBOOK_ACCESSIBLE (accessible), + gtk_notebook_get_current_page (notebook)); + gtk_widget_queue_resize (GTK_WIDGET (notebook)); gtk_widget_queue_resize (notebook->tabs_widget); g_object_notify_by_pspec (G_OBJECT (notebook), properties[PROP_PAGE]); @@ -5904,8 +5910,6 @@ gtk_notebook_set_current_page (GtkNotebook *notebook, list = g_list_nth (notebook->children, page_num); if (list) gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE_FROM_LIST (list)); - - g_object_notify_by_pspec (G_OBJECT (notebook), properties[PROP_PAGE]); } /** -- 2.30.2